// main.ts
import { Game } from './game';
import { Player } from './player';
import { animalCardsData } from './animalCards';

// 创建玩家
const players = [
  new Player(1, animalCardsData["皮溜溜"]),
  new Player(2, animalCardsData["绒可可"])
];

// 创建游戏实例
const game = new Game(players);

// 简单的游戏循环示例
console.log("游戏开始！");
while (!game.isGameOver()) {
  const gameState = game.getGameState();
  console.log(`\n当前玩家: ${gameState.currentPlayer}`);
  console.log(`牌堆剩余: ${gameState.deckSize}, 弃牌堆: ${gameState.discardPileSize}`);
  console.log(`场地卡牌: ${gameState.board.map((type, i) => type ? `${i}:${type}` : `${i}:空`).join(', ')}`);
  
  gameState.players.forEach(p => {
    console.log(`玩家${p.id}: 当前动物卡[${p.currentAnimal}], 已收集水果[${p.collectedFruits.join(',')}], 完成${p.animalsCompleted}张`);
  });

  // 简单的随机行动
  const availableActions = ['flip', 'take'];
  const action = availableActions[Math.floor(Math.random() * availableActions.length)];
  
  if (action === 'flip') {
    const availablePositions = game.board.getAvailablePositions();
    if (availablePositions.length > 0) {
      const position = availablePositions[Math.floor(Math.random() * availablePositions.length)];
      const result = game.flipCard(position);
      console.log(`玩家${gameState.currentPlayer} 翻开了位置${position}的卡牌 (类型: ${result.cardType}) - ${result.message}`);
    } else {
      console.log(`玩家${gameState.currentPlayer} 没有可翻的卡牌，回合结束`);
      game.endTurn();
    }
  } else {
    const result = game.takeAllNeededFruits();
    console.log(`玩家${gameState.currentPlayer} 尝试拿取所有需要的水果 - ${result.message}`);
  }

  // 防止无限循环
  if (gameState.deckSize + gameState.discardPileSize < 10) {
    break;
  }
}

if (game.isGameOver() && game.getWinner()) {
  console.log(`\n游戏结束！玩家${game.getWinner()!.id}获胜！`);
} else {
  console.log("\n游戏提前结束");
}